package com.lion.common.base.utils;

import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

/**
 * @author Chris Chan
 * Create On 2025/7/29 下午9:39
 * Use for: 时间工具
 * Explain:
 */
public class TimeUtil {
    public static long getCurrentTime() {
        return Instant.now().toEpochMilli();
    }

    public static String getCurrentTimeStr() {
        return String.valueOf(getCurrentTime());
    }

    public static String getCurrentTimeStrWithFormat(String format) {
        return Instant.now().atOffset(ZoneOffset.ofHours(8)).format(DateTimeFormatter.ofPattern(format));
    }

    public static Instant getCurrentInstant() {
        return Instant.now();
    }

    public static String getCurrentInstantStrWithFormat(String format) {
        return getCurrentInstant().atOffset(ZoneOffset.ofHours(8)).format(DateTimeFormatter.ofPattern(format));
    }

    // now
    public static long now() {
        return Instant.now().toEpochMilli();
    }

    public static String nowStr() {
        return nowStrWithFormat("yyyy-MM-dd HH:mm:ss");
    }

    public static String nowStrWithFormat(String format) {
        return Instant.now().atOffset(ZoneOffset.of("+8")).format(DateTimeFormatter.ofPattern(format));
    }

}
